<?php
	function is_login(){
		$CI =& get_instance();
		$CI->load->library('session');
		if(!empty($CI->session->userdata('session_user_id'))){
			return TRUE;
		}else{
			return FALSE;
		}
	}

	function is_admin(){
		$CI =& get_instance();
		$CI->load->library('session');
		if(!empty($CI->session->userdata('session_user_id')) && $CI->session->userdata('session_user_id') == 1){
			return TRUE;
		}else{
			return FALSE;
		}
	}

	function is_uploader(){
		$CI =& get_instance();
		$CI->load->library('session');
		if(!empty($CI->session->userdata('session_user_id')) && $CI->session->userdata('session_user_id') == 2){
			return TRUE;
		}else{
			return FALSE;
		}
	}

	function is_member(){
		$CI =& get_instance();
		$CI->load->library('session');
		if(!empty($CI->session->userdata('session_user_id')) && $CI->session->userdata('session_user_id') == 3){
			return TRUE;
		}else{
			return FALSE;
		}
	}

	function BEGIN_CACHE($file,$expire = '') {
		//$expire 			= 	CACHE_TIME;
		if($expire) {
			if (file_exists($file) && filemtime($file) > (time() - $expire)) {
				$html = file_get_contents($file);
				return $html;
			} else return false;
		}else {
			if (file_exists($file)) {
				$html = file_get_contents($file);
				return $html;
			} else return false;
		}
	}

	function END_CACHE($html,$file) {
		$html = SanitizeOutput($html);
		$fp = fopen($file,"w");
		$test = fputs($fp, $html);
		fclose($fp);
	}

	function SanitizeOutput($buffer) {
		$search = array(
			'/\>[^\S ]+/s',  // strip whitespaces after tags, except space
			'/[^\S ]+\</s',  // strip whitespaces before tags, except space
			'/(\s)+/s'       // shorten multiple whitespace sequences
		);
		$replace = array(
			'>',
			'<',
			'\\1'
		);
		$buffer = preg_replace($search, $replace, $buffer);
		return $buffer;
	}

